package Java_9_15zy;

import java.io.*;
import java.util.Scanner;

public class Markettest {
    public static void main(String[] args) {
        ObjectInputStream o=null;
        ObjectOutputStream o1=null;
        Market m=null;
        try {
            o = new ObjectInputStream(new FileInputStream("D:\\第一小组\\chaoshi.txt"));
                m = (Market) o.readObject();
                System.out.println(m);
        }catch (EOFException e){
            System.out.println("文件是空的");
            m = new Market("合家福", "临泉路888号", "8888888");
            System.out.println(m.toString());
            try {
                o1=new ObjectOutputStream(new FileOutputStream("D:\\第一小组\\chaoshi.txt"));
                o1.writeObject(m);
                o = new ObjectInputStream(new FileInputStream("D:\\第一小组\\chaoshi.txt"));
               m=(Market) o.readObject();

            } catch (Exception e1) {
                e1.printStackTrace();
            }finally {
                try {
                    o1.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                o.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


        System.out.println("欢迎光临合家福超市");
        Scanner in=new Scanner(System.in);
        while (true){
            System.out.println("会员开卡请按：1，会员登录请按：2，修改会员密码请按：3，退卡请按：4,剩余积分查询请按：5，积分累计请按：6，兑换请按：7，退出请按：9");
            switch (in.nextInt()){
                case 1:
                    System.out.println("请输入办卡个人信息");
                    m.addVip(new MarketVip(in.next(),in.next(),in.nextInt(),in.next(),in.next(),in.next()));
                    break;
                case 2:
                    System.out.println("请输入会员账号和密码");
                    m.dl(in.next(),in.next());
                    break;
                case 3:
                    System.out.println("请输入要修改的账户密码跟新的密码");
                    m.xg(in.next(),in.next(),in.next());
                    break;
                case 4:
                    System.out.println("请输入要退卡的账户跟密码");
                    m.yc(in.next(),in.next());
                    break;
                case 5:
                    System.out.println("请输入查询积分账号");
                    m.cx(in.next());
                    break;
                case 6:
                    System.out.println("请输入加入积分的账户和积分");
                    m.lj(in.next(),in.nextInt());
                    break;
                case 7:
                    System.out.println("请输入兑换积分账户");
                    m.dh(in.next());
                    break;
                case 9:
                    System.out.println("退出成功");
                    try {
                        o1=new ObjectOutputStream(new FileOutputStream("D:\\第一小组\\chaoshi.txt"));
                        o1.writeObject(m);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }finally {
                        try {
                            o1.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                    break;
            }
        }
    }
}
